﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FrienDev.BusinessRules;
using FrienDev.Data;

public partial class Controls_Users_ProfileContactInformationEdit : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        bt_Save.Click += new EventHandler(bt_Save_Click);
        if (!IsPostBack)
        {
            if (!UserRules.Instance.UserContactInfoExisted(UserRules.Instance.GetCurrentUserId()))
            {
                InitUserContactInfo();
            }
        }
    }

    void bt_Save_Click(object sender, EventArgs e)
    {
        System.Threading.Thread.Sleep(1000);
        if (UserRules.Instance.UserContactInfoExisted(UserRules.Instance.GetCurrentUserId()))
        {
            UserRules.Instance.InsertUserContactInfo(txt_QQ.Text.Trim(), txt_MSN.Text.Trim(), txt_TelePhone.Text.Trim(), txt_MobilePhone.Text.Trim(), txt_Fax.Text.Trim());
        }
        else
        {
            UserRules.Instance.UpdateUserContactInfo(txt_QQ.Text.Trim(), txt_MSN.Text.Trim(), txt_TelePhone.Text.Trim(), txt_MobilePhone.Text.Trim(), txt_Fax.Text.Trim());
        }
        up_UserContactInfoForm.Update();
    }

    private void InitUserContactInfo()
    {
        User user = UserRules.Instance.GetCurrentUser();
        txt_QQ.Text = user.UsersContact.QQ.ToString();
        txt_MSN.Text = user.UsersContact.MSN.ToString();
        txt_TelePhone.Text = user.UsersContact.Phone.ToString();
        txt_MobilePhone.Text = user.UsersContact.MobilePhone.ToString();
        txt_Fax.Text = user.UsersContact.Fax.ToString();
    }
}
